package com.heima.tess4j;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

/**
 * 识别图片中的文字
 */
public class Application {
    public static void main(String[] args) throws TesseractException {
        // 创建实例
        ITesseract tesseract = new Tesseract();
        // 设置字体库路径
        tesseract.setDatapath("D:\\workspace");
        // 设置语言
        tesseract.setLanguage("chi_sim");
        // 识别图片
        File file = new File("D:\\143.png");
        String result = tesseract.doOCR(file);
        System.out.println("识别结果为：" + result.replaceAll("\\r|\\n","-"));
        System.out.println("===============================================");
        System.out.println(result);
    }
}
